pandas.Series
de índice horario con datos de consumo en kWh.esiosdata.FacturaElec
In [9]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
from glob import glob
import matplotlib.pyplot as plt
import os
import pandas as pd
import requests
from esiosdata import FacturaElec
from esiosdata.prettyprinting import *
# enerPI JSON API
ip_enerpi = '192.168.1.44'
t0, tf = '2016-11-01', '2016-12-24'
url = 'http://{}/enerpi/api/consumption/from/{}/to/{}'.format(ip_enerpi, t0, tf)
print(url)
r = requests.get(url)
if r.ok:
data = r.json()
data_consumo = pd.DataFrame(pd.Series(data, name='kWh')).sort_index().reset_index()
data_consumo.index = data_consumo['index'].apply(lambda x: pd.Timestamp.fromtimestamp(float(x) / 1000.))
data_consumo.drop('index', axis=1, inplace=True)
print_ok(data_consumo.head())
print_ok(data_consumo.tail())
else:
print_err(r)
In [2]:
# Consumo Total en intervalo:
c_tot = round(data_consumo.kWh.round(3).sum(), 3)
print_ok(c_tot)
# Plot consumo diario en kWh
data_consumo.kWh.resample('D').sum().plot(figsize=(16, 9));
In [3]:
factura = FacturaElec(consumo=data_consumo.kWh)
print_info(factura)
In [4]:
factura.tipo_peaje = 2
print_cyan(factura)
In [5]:
factura.tipo_peaje = 3
print_magenta(factura)
In [6]:
path_csv = os.path.expanduser('~/Desktop/')
df_csv = factura.generacion_csv_oficial_consumo_horario(path_csv)
print_ok(df_csv.tail())
file_path = glob(path_csv + '*.csv')[0]
with open(file_path, 'r') as f:
print_magenta(f.read()[:500])
In [7]:
print_ok('Consumo diario')
factura.plot_consumo_diario()
plt.show()
In [8]:
print_ok('Patrón de consumo semanal')
factura.plot_patron_semanal_consumo()
plt.show()